import '../Include.dart';

class GuideView extends StatelessWidget {
  final String data;
  final List<String> guideImages;
  final VoidCallback onPressed;

  const GuideView(
      {Key key,
      @required this.data,
      @required this.guideImages,
      @required this.onPressed})
      : super(key: key);

  List<Widget> getWidgets() {
    List<Widget> widgets = List();
    for (int i = 0; i < guideImages.length; i++) {
      Widget widget;
      if (i == guideImages.length - 1) {
        widget = Stack(
          alignment: AlignmentDirectional.center,
          children: <Widget>[
            _buildGuide(guideImages.elementAt(i)),
            Align(
              child: Padding(
                padding: EdgeInsets.only(bottom: 48),
                child: FlatButton(
                  onPressed: onPressed,
                  padding: EdgeInsets.only(left: 32,top: 8,right: 32,bottom: 8),
                  color: Colors.black12,
                  shape: StadiumBorder(),
                  child: Text(
                    data,
                    style: TextStyle(
                      color: Colors.white,
                      fontSize: 18,
                    ),
                  ),
                ),
              ),
              alignment: Alignment.bottomCenter,
            )
          ],
        );
      } else {
        widget = _buildGuide(guideImages.elementAt(i));
      }
      widgets.add(widget);
    }
    return widgets;
  }

  Widget _buildGuide(String name) {
    return ConstrainedBox(
      child: JvtdImageUtils.getLocalImage(
        name: name,
        fit: BoxFit.fitHeight,
      ),
      constraints: new BoxConstraints.expand(), //填充父布局
    );
  }

  @override
  Widget build(BuildContext context) {
    return PageView(
      children: getWidgets(),
      controller: PageController(),
    );
  }
}
